import 'package:flutter/material.dart';


//一个可以嵌套其它可滚动widget的widget
class NestedScrollViewEx extends StatefulWidget{
@override
State<StatefulWidget> createState() {
  return _NestedScrollViewEx();
}
}

class _NestedScrollViewEx extends State<NestedScrollViewEx>
{
  final List<String> _tabs = <String>['Tab1', 'Tab2'];
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(length: _tabs.length,
        child: Scaffold(
          body: NestedScrollView(headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled){
            return <Widget>[
              SliverOverlapAbsorber(handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
              sliver: SliverAppBar(title: const Text('Books'),
              pinned: true,
              expandedHeight: 150.0,
              forceElevated: innerBoxIsScrolled,
              bottom: TabBar(tabs: _tabs.map((String name) => Tab(text:name)).toList()),),),
            ];
          }, body: TabBarView(children: _tabs.map((String name){
            return SafeArea(child: Builder(
              builder: (BuildContext context){
                return CustomScrollView(
                  key: PageStorageKey<String>(name),
                  slivers: [
                    SliverOverlapInjector(handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context)),
                    SliverPadding(padding: const EdgeInsets.all(8.0),
                    sliver: SliverFixedExtentList(
                      itemExtent: 48.0,
                      delegate: SliverChildBuilderDelegate(
                          (BuildContext context, int index){
                            return ListTile(title:Text('Item $index'));
                          },
                        childCount: 30,
                      ),
                    ),)
                  ],
                );
              },
            ),);
          }).toList())),
        ));
  }
}